package dd.control;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.NodeList;

import xml.Message;
import dd.model.Event;
import dd.model.Model;
import dd.view.AdminScreen;

public class EventsResponseController {

	public void process(Message response) {
		List<Event> events = new ArrayList<Event>();

		NodeList eventList = response.contents.getFirstChild().getChildNodes();
		for (int i = 0; i < eventList.getLength(); i++) {
			String id = eventList.item(i).getAttributes().getNamedItem("id").getNodeValue();
			String name = eventList.item(i).getAttributes().getNamedItem("name").getNodeValue();
			Event event = new Event();
			event.setEventID(id);
			event.setEventName(name);
			events.add(event);
		}

		AdminScreen adminScreen = new AdminScreen(events);
		adminScreen.setVisible(true);

		Model.getInstance().getMainScreen().dispose();
	}
}
